/**
 * 
 */
package com.app.mvc.action;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.app.service.AjaxServiceFacade;
import com.app.service.IAjaxService;
import com.app.util.JSONParse;

/**
 * @author Administrator
 * 接受ajax请求
 */
@Controller
@RequestMapping(value="/ajax")
public class AjaxAction {

	/**
	 * 
	 */
	public AjaxAction() {
	}
	@Autowired
	private AjaxServiceFacade ajaxfacade;
	
	@RequestMapping
	public String validate(@RequestParam(value="key") String key,HttpServletResponse response,HttpServletRequest request)
	{
		try {
			IAjaxService ajax =this.ajaxfacade.getAjaxService(key);
			Map<?,?> params = ajax.execute(request);
			response.getWriter().println(JSONParse.parseJson(params));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public AjaxServiceFacade getAjaxfacade() {
		return ajaxfacade;
	}

	public void setAjaxfacade(AjaxServiceFacade ajaxfacade) {
		this.ajaxfacade = ajaxfacade;
	}
	
	
	

}
